
function start_gb28181()
{


	ps -fe|grep gb28181 |grep -v grep
	if [ $? -ne 0 ]
	then
		/root/gb28181 &
	fi

}
function stop_gb28181()
{
	pkill -9 gb28181
}

function start_bsp()
{

	ps -fe|grep bsp.exe |grep -v grep
	if [ $? -ne 0 ]
	then
       		/root/bsp.exe &
	fi

}
function start_pushstream()
{

	ps -fe|grep pushstream.exe |grep -v grep	
	if [ $? -ne 0 ]
	then
		/root/pushstream.exe &
	fi
}
function stop_pushstream()
{

	pkill -9  pushstream.exe
}
function start_http()
{

	ps -fe|grep mongoose |grep -v grep
	if [ $? -ne 0 ]
	then
      		 /root/mongoose &
	fi

}
function start_pull()
{
	
	proto=$(jq -r '.videoFrom' /home/Config/decsource.json)
	if [ $proto = "srt" ]; then	
		ps -fe|grep srt-live-recv |grep -v grep
		if [ $? -ne 0 ]
		then
			url=$(jq -r '.videoSourceUrl' /home/Config/decsource.json)
			if [ -n "$proto" ];then
				srt-live-recv $url udp://127.0.0.1:7788 &
			fi						
		fi
	fi


}
function start_mqtt()
{
	ps -fe|grep mqtt.exe |grep -v grep
        if [ $? -ne 0 ]
        then
                 /root/mqtt.exe &
        fi


}
function start_codec()
{

	ps -fe|grep codec.exe |grep -v grep
	if [ $? -ne 0 ]
	then
		stop_gb28181
		stop_pushstream
		/root/codec.exe &
		sleep 1
		start_pushstream
		start_gb28181
		start_http
		start_pull	
	else
		start_pushstream
		start_gb28181
		start_http	
		start_pull
	fi
	start_mqtt
	start_bsp
}

start_codec
